﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MINERP.NewPB.IView;
using MINERP.MODEL.FoundationModel;
using MINERP.BLL.NewPB;

namespace MINERP.NewPB.Presenter
{
    public class SelectPrinterPresenter
    {
        private ISelectPrinterView _view;
        private List<Printer_Info> _ListPrinter;//用于缓存打印机的数据
        private NewPBBLL _bll;

        public SelectPrinterPresenter(ISelectPrinterView view)
        {
            _view = view;
            _bll = new NewPBBLL();
            IntilPrinter();
        }

        //初始化打印机下拉列表数据
        void IntilPrinter()
        {
            if (_ListPrinter==null||_ListPrinter.Count<1)
            {
                _ListPrinter = _bll.GetAllPrinter();
            }
            if (_ListPrinter!=null)
            {
                _view.BindCmbPrinter(_ListPrinter);
            }
        }

        //选择某一打印机后事件
        internal void SelectedPrinter()
        {
            Printer_Info pi = null;
            int printerId = _view.SelectedPrinterId;
            if (printerId>0)
            {
               pi= _ListPrinter.FirstOrDefault(lp => lp.PrinterID == printerId);
               if (pi==null)
               {
                   System.Windows.Forms.MessageBox.Show("请选择正确的打印机!");
               }
               else
               {
                   DataTransfer.CurPrinter = pi;
               }
               _view.CloseIt();
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("请选择正确的打印机!");
            }
        }
    }
}
